#include "SingletonTest.h"
#include <iostream>
#include <string>
// #include <stdio.h>
using namespace std;

SingletonTest *SingletonTest::value = nullptr;
pthread_once_t SingletonTest::ponce = PTHREAD_ONCE_INIT;

void singletonTest();
void lambdaTest(int val1, string str1);

int main(int argc, char const *argv[])
{
    // singletonTest();
    lambdaTest(123, "hahahah");

    return 0;
}

void lambdaTest(int val1, string str1) {
    auto f = [&]        // 以引用方式捕获作用域中的变量
    {
        cout << "val1: " << val1 << endl;
        cout << "str1: " << str1 << endl;
    };

    f();
}

void singletonTest() {
    // &
    // 要用引用变量接收一个返回引用值的表达式
    SingletonTest &in1 = SingletonTest::instance();
    SingletonTest &in2 = SingletonTest::instance();
    // printf("%#x --\n", &in1);
    // printf("%#x --\n", &in2);
  
    cout << &in1 << endl;
    cout << &in2 << endl;
     
    // ----------------------------------------------
    // *
    SingletonTest *in_p1 = SingletonTest::instance_p();
    SingletonTest *in_p2 = SingletonTest::instance_p();

    cout << in_p1 << endl;
    cout << in_p2 << endl;
}
